using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using Framework.Module.CMS.Library.Distributions;
using Framework.Module.CMS.Library.Definitions;
using Framework.Library.Utilities;
using Framework.Module.CMS.Library;
using Framework.Module.CMS.Library.Zones;

namespace Framework.Module.CMS.Web.HomePage
{
    public partial class HeadZone : CMSWebControl
    {
        protected string zoneurl = "";
        private int _zoneid = 0;
        private ZoneInfo zoneinfo = null;

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        public void LoadZone(int zoneid)
        {
            zoneinfo = ZoneController.GetZone(zoneid);
            if (zoneinfo != null)
            {
                this._zoneid = zoneid;
                this.lab_ZoneTitle.Text = zoneinfo.Zone_Name;

                this.zoneurl = BuildUrlByZone(this.zoneinfo.Zone_ID, this.zoneinfo.Portal_TabControlID);

                DataTable tbl = DistributionController.GetDistributedContents(zoneid, 2, (int)CMSDistributionRank.Default);
                if (tbl != null && tbl.Rows.Count > 0)
                {
                    this.rpt_head.DataSource = tbl;
                    this.rpt_head.DataBind();

                    DataTable tblsub = DistributionController.GetDistributedContents(zoneid, 10, (int)CMSDistributionRank.Default);
                    if (tblsub != null && tblsub.Rows.Count > 0)
                    {
                        tblsub.Rows.RemoveAt(0);
                        
                        if (tblsub.Rows.Count > 0)
                            tblsub.Rows.RemoveAt(0);
                        else
                            return;

                        this.rpt_foot.DataSource = tblsub;
                        this.rpt_foot.DataBind();
                    }
                }
                else
                {
                    this.Visible = false;
                }
            }
            else
            {
                this.Visible = false;
            }
        }

        protected void rpt_foot_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                DataRowView currow = (DataRowView)e.Item.DataItem;
                if (currow != null)
                {
                    HyperLink hplTitle = (HyperLink)e.Item.FindControl("link");
                 

                    //string tooltip = MiscUtility.ToolTip(ConvertUtility.ToString(currow["Content_Headline"]), ConvertUtility.ToString(currow["Content_SubTitle"]), ConvertUtility.ToString(currow["Content_Avatar"]), ConvertUtility.ToString(currow["Content_Teaser"]), ConvertUtility.ToString(currow["Content_Alias"]), ConvertUtility.ToDateTime(currow["Distribution_CreateDate"]));
                    hplTitle.Attributes.Add("onmouseover", "setVisibility(event,'" + currow["Distribution_ID"] + "', 'inline');");
                    hplTitle.Attributes.Add("onmouseout", "setVisibility(event,'" + currow["Distribution_ID"] + "', 'none');");
                    hplTitle.Attributes.Add("class", "chuyenmuc_tomtattindau");
                    hplTitle.Text = ConvertUtility.ToString(currow["Content_Headline"]);
                    hplTitle.NavigateUrl = BuildUrlByDistId((int)currow["Distribution_ID"], this._zoneid);
                    Image img = (Image)e.Item.FindControl("foter_img");
                    if (!string.IsNullOrEmpty(currow["Content_Avatar"].ToString()))
                    {
                        img.ImageUrl = MultimediaUtility.GetListAvatar(currow["Content_Avatar"].ToString());
                    }
                }
            }
        }

        protected void rpt_head_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            DataRowView row = (DataRowView)e.Item.DataItem;
            if (row != null)
            {
                int distid = ConvertUtility.ToInt32(row["Distribution_ID"]);

                Image img = (Image)e.Item.FindControl("img_img");
                if (!string.IsNullOrEmpty(row["Content_Avatar"].ToString()))
                {
                    img.ImageUrl = MultimediaUtility.GetListAvatar(row["Content_Avatar"].ToString());
                }
                else
                {
                    img.ImageUrl = "/images/avata.gif";
                }
                img.Attributes.Add("onclick", "javascript:window.location='" + BuildUrlByDistId(distid, this._zoneid) + "'");
                img.Attributes.Add("style", "cursor:hand");

                HyperLink link1 = (HyperLink)e.Item.FindControl("link1");

                link1.Text = ConvertUtility.ToString(row["Content_Headline"]);
                link1.NavigateUrl = BuildUrlByDistId((int)row["Distribution_ID"], this._zoneid);

                HyperLink link2 = (HyperLink)e.Item.FindControl("link2");

                link2.NavigateUrl = BuildUrlByDistId((int)row["Distribution_ID"], this._zoneid);
            }
        }
    }
}